<!DOCTYPE html>

<html lang="zh">

<head>
    <meta charset="UTF-8">
    <title>登录</title>
    <link rel="stylesheet" href="jamcss/login.css">
    <link rel="stylesheet" href="jamcss/font-awesome.css">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=yes">
    <script type="text/javascript" src="jamjs/jquery-1.11.0.js"></script>
    <script type="text/javascript" src="jamjs/jquery.cookie.js"></script>

<!--    <style>-->
<!--        .input {-->
<!--            color: green;-->
<!--            width: auto;-->
<!--    min-width: 20px;-->
<!--    font-size: 18px;-->
<!--    border: 0;-->
<!--    border-bottom: 1px solid red;-->
<!--    padding: 5px 10px;-->
<!--    background: #ffffff00;-->
<!--        }-->


<!--    </style>-->
</head>

<body>
    <div id="login-box">
        <h1>Login</h1>
        <div class="form">
            <div class="item">
<!--                <i class="fa fa-key" aria-hidden="true"></i>-->
                <input id="username" type="text" autocomplete="on" value="JamLogin" hidden>
                <input id="password" type="password" onkeydown="login_check()" autocomplete="on" placeholder="需要密码" name="password">
            </div>
        </div>
        <div>
            <input type="checkbox" style="margin-top: 15px" id="savelogin"  checked="checked" onchange="SaveLoginChange()">保存登录状态
        </div>

        <button type="button" onclick="LoginClick()">登录</button>
        <button type="button" onclick="window.close()">取消</button>
    </div>
<script>

    // 请求路径
    var httpurl = "/loginrequest";


    // 数据请求
    function LoginClick() {
        var passwordstr = document.getElementById("password").value;
        if(passwordstr===""||passwordstr==null){
            alert("请输入密码");
            return;
        }

        $.ajax({
            url: httpurl,//请求的url地址
            method: 'post',//设置请求的http方式，method也可以
            dataType: 'json',//将服务器端返回的数据直接认定为是这个格式，然后会做一些自动的处理(如果是json字符串，会自动转化为js对象),服务器返回的默认格式是text/html格式
            data: JSON.stringify({//向服务器端发送的数据
                password: passwordstr,
                requesttype: 'login',
            }),
            success: function (data, textStatus, jqXHR) {//请求成功之后执行的回调函数
                console.log(jqXHR,jqXHR.status,data)
                if (jqXHR.readyState === 4 && jqXHR.status === 200) {
                    console.log("success",data,typeof data)
                    var obj = data;
                    $.cookie("p9az", obj.p9az, {
                  expires: 30,//设置保存期限  7天
                  path: "/"//设置保存的路径
                    });
                    $.cookie("p2iix9ab", obj.p2iix9ab, {
                  expires: 30,//设置保存期限  30
                  path: "/"//设置保存的路径
                    });
                    location.href = "/home";
                } else {
                    console.log("密码错误")
                    alert("密码错误!")
                }
            },
            error: function (jqXHR, textStatus, errorThrown) {//请求失败之后执行的回调函数
                alert("无法访问!")
                console.log(errorThrown,jqXHR,textStatus);
            }
        });
        console.log("fffffffffffffffffdss");
    }
    function login_check(frm,event){

    event=window.event?window.event:event;
   console.log(event.keyCode)
    if(event.keyCode==13){
        LoginClick()
    }

    }

    function SaveLoginChange(){
        console.log("change")
        if (!$(":checkbox[id='savelogin']").prop("checked")){
            console.log("not checked")
            document.cookie= "p9az=; expires=Thu, 01 Jan 1970 00:00:00 GMT";
            document.cookie= "p2iix9ab=; expires=Thu, 01 Jan 1970 00:00:00 GMT";//清除cookie
        }
    }

</script>

</body>

<footer>
    <div id="message-box">
        <p>Posted by: JamTools<br />Contact information: <a href="fandesfyf@qq.com">fandesfyf@qq.com</a>.</p></div>

</footer>

</html>